package com.youfan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.youfan.entity.ProductattributeCa;
import com.youfan.mapper.ProductAttrctMapper;
import com.youfan.page.CommonPage;
import com.youfan.service.ProductAttrCtService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


@Service
public class ProductattrCtServiceImpl extends ServiceImpl<ProductAttrctMapper, ProductattributeCa> implements ProductAttrCtService {

    @Autowired
    private ProductAttrctMapper productAttrctMapper;




    @Override
    public int insertOne(ProductattributeCa youfanProductattributeCa) {
        youfanProductattributeCa.setCreateTime(new Date());
        return productAttrctMapper.insert(youfanProductattributeCa);
    }

    @Override
    public CommonPage<ProductattributeCa> queryByCondtion(ProductattributeCa youfanProductattributeCa) {
        PageHelper.startPage(youfanProductattributeCa.getPageNum(),youfanProductattributeCa.getPageSize());
        QueryWrapper queryWrapper = new QueryWrapper();
        if(StringUtils.isNotBlank(youfanProductattributeCa.getName())){
            queryWrapper.like("name", youfanProductattributeCa.getName());
        }
        if(StringUtils.isNotBlank(youfanProductattributeCa.getAttributedesc())){
            queryWrapper.like("attributedes",youfanProductattributeCa.getAttributedesc());
        }



        List<ProductattributeCa> list = productAttrctMapper.selectList(queryWrapper);


        return CommonPage.restPage(list);
    }

    @Override
    public ProductattributeCa findByid(ProductattributeCa youfanProductattributeCa) {
        return productAttrctMapper.selectById(youfanProductattributeCa.getId());
    }

    @Override
    public int updateOne(ProductattributeCa youfanProductattributeCa) {
        return productAttrctMapper.updateById(youfanProductattributeCa);
    }
}
